package com.example.module_marketers

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.view.BaseMvvmActivity
import com.example.module_marketers.adapter.ResidencyApplicationAdapter
import com.example.module_marketers.databinding.ActivityResidencyApplicationBinding
import com.example.module_marketers.viewmodel.MarketersViewModel
/**
 * 智慧园区-04-商家推荐V1.1-张亦婷-20250512
 */
@Route(path = "/module_marketers/residencyApplicationActivity")
class ResidencyApplicationActivity : BaseMvvmActivity<ActivityResidencyApplicationBinding>() {
    private val viewModel: MarketersViewModel by viewModels()
    lateinit var residencyApplicationAdapter: ResidencyApplicationAdapter
    override fun initViews() {
        super.initViews()
        binding.ivBack.setOnClickListener {
            finish()
        }
        residencyApplicationAdapter= ResidencyApplicationAdapter()
        binding.rvResidencyApplication.adapter=residencyApplicationAdapter
        binding.rvResidencyApplication.layoutManager= LinearLayoutManager(this)
        viewModel.getResidencyApplicationList()
        residencyApplicationAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/module_marketers/residencyApplicationDetailActivity")
                .withInt("detailId",residencyApplicationAdapter.data[position].id)
                .navigation()
        }
    }
    override fun observeDataChange() {
        viewModel.getResidencyApplicationListSuccess.observe(this){
            residencyApplicationAdapter.data.clear()
            residencyApplicationAdapter.data.addAll(it)
            residencyApplicationAdapter.notifyDataSetChanged()
        }
    }

    override fun getLayoutId(): Int =R.layout.activity_residency_application
}